using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using DTO;
using System.Data;

namespace HeThongDAO
{
    public class ChiTietHoaDonDAO
    {
  

        public static DataTable LayDanhSachChiTietHoaDon()
        {
            string sql = "SELECT * FROM CHI_TIET_HOA_DON";
            return Config.AccessHelper.ExecuteQuery(sql);
        }

        public static bool ThemChiTietHoaDon(ChiTietHoaDonDTO cthdDTO)
        {
            try
            {
                string sql = "INSERT INTO CHI_TIET_HOA_DON(MaHoaDon, MaSach, SoLuong, DonGia) ";
                sql += "VALUES(" + cthdDTO.MaHoaDon.ToString() + ",";
                sql += cthdDTO.MaSach.ToString() + ",";
                sql += cthdDTO.SoLuong.ToString() + ",";
                sql += cthdDTO.DonGia.ToString() + ")";

                Config.AccessHelper.ExecuteNonQuery(sql);

                return true;
            }
            catch
            {
                return false;
            }
        }

        public static bool CapNhatChiTietHoaDon(ChiTietHoaDonDTO cthdDTO)
        {
            try
            {
                string sql = "UPDATE CHI_TIET_HOA_DON SET ";
                sql += "MaHoaDon = " + cthdDTO.MaHoaDon + ", ";
                sql += "MaSach = " + cthdDTO.MaSach + ", ";
                sql += "SoLuong = " + cthdDTO.SoLuong + ", ";
                sql += "DonGia = " + cthdDTO.DonGia;
                sql += " WHERE MaChiTietHoaDon = " + cthdDTO.MaChiTietHoaDon;

                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public static bool XoaChiTietHoaDon(ChiTietHoaDonDTO cthdDTO)
        {
            try
            {
                string sql = "DELETE FROM CHI_TIET_HOA_DON ";
                sql += "WHERE MaChiTietHoaDon = " + cthdDTO.MaChiTietHoaDon;

                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public static DataTable DocSchema()
        {
            return Config.AccessHelper.Doc_Cau_Truc("CHI_TIET_HOA_DON");
        }
    }
}
